package com.yanqu.road.server.cmd.beautyescort;

import com.yanqu.road.entity.beautyescort.EscortBeautyDispatch;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.beautyescort.BeautyEscortProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.beautyescort.CrossBeautyEscortMgr;
import com.yanqu.road.server.manager.beautyescort.CrossEscortPlayerWrap;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

@Cmd(code = Protocol.C_BEAUTY_ESCORT_DART_ACCEPT_DISPATCH_BEAUTY_TEN, desc = "接镖+美女派遣(十连)")
public class CrossBeautyEscortAcceptDispatchDartTenCmd extends CrossCommand {

    private int client;
    private int type;
    private List<EscortBeautyDispatch> dispatchList;
    private long playerId;
    private String allConsume;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BeautyEscortProto.CrossBeautyEscortAcceptDispatchTenReqMsg reqMsg = BeautyEscortProto.CrossBeautyEscortAcceptDispatchTenReqMsg.parseFrom(packet.getBytes());
        client = reqMsg.getClient();
        type = reqMsg.getTypeId();
        playerId = packet.getPlayerId();
        dispatchList = CrossBeautyEscortMgr.parseBeautyDispatch(reqMsg.getBeautyList());
        allConsume = reqMsg.getAllConsume();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossEscortPlayerWrap escortPlayer = CrossBeautyEscortMgr.getEscortPlayer(serverId, packet.getPlayerId());
        if(escortPlayer != null){
            ret = escortPlayer.acceptAndDispatchDartTenTimes(client, type, dispatchList, allConsume);
        }else{
            ret = GameErrorCode.E_BEAUTY_ESCORT_USER_NOT_FOUND;
        }
    }

    @Override
    public void sendData() {
        if(ret != 0){
            BeautyEscortProto.CrossBeautyEscortAcceptDispatchTenRespMsg.Builder respMsg = BeautyEscortProto.CrossBeautyEscortAcceptDispatchTenRespMsg.newBuilder();
            respMsg.setRet(ret);
            respMsg.setAllConsume(allConsume);
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.S_BEAUTY_ESCORT_ACCEPT_DISPATCH_BEAUTY_TEN_TIMES_FROM_CROSS, respMsg));
        }
    }
}
